package com.wxapp.common.util.check;

import com.wxapp.common.constant.base.IBaseEnum;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author lgl
 * @Description 检查类
 * @Datetime 2022/5/30 14:53
 * @Modified By
 */
public class CheckUtil {
    private CheckUtil() {}

    /**
     * 判断数组不为空
     */
    @SafeVarargs
    public static <T> boolean isNotNullArray(T... object) {
        return !isNullArray(object);
    }

    /**
     * 判断数组不为空
     */
    @SafeVarargs
    public static <T> boolean isNullArray(T... object) {
        return object == null || object.length == 0;
    }

    /**
     * TODO: 判断list不为空
     */
    public static boolean isNotNullList(List list) {
        return !isNullList(list);
    }

    /**
     * TODO: list为空
     */
    public static boolean isNullList(List list) {
        return list == null || list.isEmpty();
    }

    /**
     *  判断Map不为空
     */
    public static boolean isNotNullMap(Map map) {
        return !isNullMap(map);
    }

    /**
     * 判断Map不为空
     */
    public static boolean isNullMap(Map map) {
        return map == null || map.isEmpty();
    }

    /**
     *  object不为空
     */
    public static boolean isNotNullObject(Object object) {
        return !isNullObject(object);
    }

    /**
     *   object 为空
     */
    public static boolean isNullObject(Object object) {
        return object == null || isNullString(String.valueOf(object));
    }

    /**
     *  字符串不为空
     */
    public static boolean isNotNullString(String vm) {
        return !isNullString(vm);
    }
    public static  boolean isNullEnum(Object vm) {
        if (vm==null){
            return true;
        }
        if (vm !=null && vm instanceof IBaseEnum<?>){
            return isNullObject(((IBaseEnum<?>) vm).getValue());
        }
       return false;
    }
    public static <T extends IBaseEnum<String>> boolean isNotNullEnum(T vm) {
        return !isNullEnum(vm);
    }
    public static boolean isNullString(final CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0 || "null".contentEquals(cs) || "NULL".contentEquals(cs)) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(cs.charAt(i))) {
                return false;
            }
        }
        return true;
    }
    public static boolean isNotNullBigDecimal(BigDecimal bd){
        return !isNullBigDecimal(bd);
    }

    public static boolean isNullBigDecimal(BigDecimal bd) {
        if (bd == null || bd.compareTo(BigDecimal.ZERO) == 0){
            return true;
        }
        return false;
    }
}
